<?php
include 'topo.php';

if(!isset($_GET["id"]))
{
    header("location:proprietario.php");
}
$id = $_GET["id"];

$sql = "SELECT * FROM proprietario WHERE id=$id";
$res = pg_query($sql);
$item = pg_fetch_assoc($res);



$sql = "SELECT * from fazenda order by nome";
$res = pg_query($sql);
while($linha = pg_fetch_assoc($res))
{
    $id = $linha["id"];
    $nome = $linha["nome"];
    if($item["minhafazendaid"]==$linha["id"])
    {
        $optFazenda.= "<option selected value='$id'>$nome</option>";
    }
    else
    {
        $optFazenda.= "<option value='$id'>$nome</option>";
    }
    
}


 
?>
        
        <div style="text-align:center;font-family: arial">


            <form action="proprietario-alterar-ok.php" method="post">
                <input type="hidden" name="id" value="<?php echo $item["id"]; ?>" />
                <table border="0" cellpadding="0" cellspacing="0" width="25%">
                    <tr> 
                        <td width="30%">Nome:</td>
                        <td width="70%"><input type="text" name="nome" value="<?php echo $item["nome"]; ?>"
                            required/></td>
                    </tr> 
                    <tr> 
                        <td width="30%">Fone:</td>
                        <td width="70%">
                        <input style="width:25px" type="text" value="<?php echo substr($item["fone"], 0,2); ?>" name="fone1"/>
                        <input style="width:207px" type="text" value="<?php echo substr($item["fone"], 2); ?>"  name="fone2"/>

                        </td>
                    </tr>
                     <tr> 
                        <td width="30%">Fazenda:</td>
                        <td width="70%">
                        <select name="minhafazendaid">
                            <option value="">selecione</option>
                            <?php echo $optFazenda?>
                        </select>
                        </td>
                    </tr>
                     <tr> 
                        <td width="30%">Avatar:</td>
                        <td width="70%">
                        <input type="text" value="<?php echo $item["avatar"]; ?>" name="avatar"/>
                        </td>
                    </tr>
                    <tr>
                        <td width="30%">Brasileiro:</td>
                        <td width="70%">
                            <input type="radio" name="brasileiro" <?php if($item["brasileiro"]=="Sim") echo "checked"; ?> value="Sim" />Sim
                            <input type="radio" name="brasileiro" <?php if($item["brasileiro"]=="Não") echo "checked"; ?> value="Não" />Não
                            <input type="radio" name="brasileiro" <?php if($item["brasileiro"]=="Naturalizado") echo "checked"; ?> value="Naturalizado" />Naturalizado
                        </td>
                    </tr> 
                    <tr>
                        <td align="right" colspan='2'> 
                            <input type="submit" name="bot_enviar" value="Alterar"/> 
                        </td> 
                    </tr> 
                </table> 
            </form>	


        </div>
    </body>
</html>